<?php

	class Controller_Monetization extends Controller_Abstract
	{
	
		function actionIndex()
		{
			if(isset($_SESSION['infos'])){
				$this->_view['infos'] = $_SESSION['infos'];
				unset($_SESSION['infos']);
			}
	        $monetization = new Monetization();
	        $this->_view['monetizations'] = $monetization->getAllMonetizations();
		}
		
		function actionInsert(){
			if($this->_context->isPOST()){
				$errors = array();
				$name = $this->_context->name;
				$note = $this->_context->note;
				$html = $this->_context->html;
				$secretKey = $this->_context->secret_key;
				$appId = $this->_context->app_id;
				$monetization = new Monetization();
				$result = $monetization->add($name, $note, $html, $secretKey, $appId);	
				if($result)
					$_SESSION['infos'][] = Util::getMessage(6001);							
				return $this->_redirect(url('monetization/index'));
			}
		}
		
		function actionUpdate(){
			$id = isset($this->_context->id) ? intval($this->_context->id) : '';
			if($this->_context->isPOST()){
				$errors = array();
				if($id){
					$name = $this->_context->name;
					$note = $this->_context->note;
					$html = $this->_context->html;
					$secretKey = $this->_context->secret_key;
					$appId = $this->_context->app_id;
					$monetization = new Monetization();
					$monetization->update($name, $note, $html, $secretKey, $appId, $id);					
					return $this->_redirect(url('monetization/index'));
				}
			}elseif($this->_context->isGET()){
				if($id){
					$monetization = new Monetization();
					$this->_view['monetization'] = $monetization->getMonetizationById($id);
				}
			}
		}
		
		function actionDelete(){
			$id = isset($this->_context->id) ? intval($this->_context->id) : '';
			if($id){
				$monetization = new Monetization();
				$monetization->delete($id);
				return $this->_redirect(url('monetization/index'));
			}
		}
		
	}


